package practice;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 开源项目热榜
 */
public class OpenSourceProjectList {

    static class Project {

        String name;


        Integer mark;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getMark() {
            return mark;
        }

        public void setMark(Integer mark) {
            this.mark = mark;
        }


    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = Integer.parseInt(sc.nextLine());
            String[] strs = sc.nextLine().split(" ");
            int[] weights = covertToIntArr(strs);
            List<Project> result = new ArrayList<>(n);
            for (int i = 0; i < n; i++) {
                List<String> marks = Arrays.stream(sc.nextLine().split(" "))
                        .collect(Collectors.toList());
                Project project = new Project();
                marks.stream().findFirst()
                        .ifPresent(project::setName);
                marks.remove(0);
                int total = IntStream.range(0, weights.length)
                        .map(j -> weights[j] * Integer.parseInt(marks.get(j)))
                        .sum();
                project.setMark(total);
                result.add(project);
            }
            // 根据mark字段降序排序
            Comparator<Project> byMarkDesc = Comparator.comparingInt(Project::getMark).reversed();

            // 根据name字段升序排序
            Comparator<Project> byNameAsc = Comparator.comparing(Project::getName);

            // 组合两个Comparator
            Comparator<Project> combinedComparator = byMarkDesc.thenComparing(byNameAsc);

            result.sort(combinedComparator);
            result
                    .forEach(pro -> System.out.println(pro.getName() + "-->" + pro.getMark()));
        }
    }

    public static int[] covertToIntArr(String[] strs) {
        return Arrays.stream(strs)
                .mapToInt(Integer::parseInt)
                .toArray();
    }
}
